<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="div"></div>
    <script src="./jquery.min.js"></script>
    <script>
        var div = $('.div');
        var arr1 = [1, 2, 3, 4, 5];
        var obj1 = {
            name: 'Tom',
            age: 18,
            job: 'student',
            hasWude: false
        }
        var res = [
            { "productName": "空气进化器", "nums": 21 },
            { "productName": "吸尘器", "nums": 21 },
            { "productName": "扫地机器人", "nums": 21 },
            { "productName": "电风扇", "nums": 21 },
            { "productName": "净水壶", "nums": 21 },
            { "productName": "电饭煲", "nums": 21 },
            { "productName": "咖啡机", "nums": 21 },
            { "productName": "原汁机", "nums": 21 },
            { "productName": "电视机", "nums": 21 },
            { "productName": "空凋", "nums": 21 },
            { "productName": "洗衣机", "nums": 21 },
            { "productName": "加湿器", "nums": 21 },
            { "productName": "净水壶", "nums": 21 },
            { "productName": "热水器", "nums": 21 }
        ]
        // 遍历数组 打印内容
        // $.each(arr1, function (index, num) {
        //     console.log(index);
        //     console.log(num);
        // })
        // // 遍历对象
        // $.each(obj1, function (key, val) {
        //     console.log(key, val);
        // })
        // 遍历后台的数据，格式是一个数组
        var content = '';
        $.each(res, function(i, goods) {
            // 拼接字符串 准备好内容
            content += `<div>`+goods.productName+'</div>'
        })
        // 通过html方法 将内容加到指定元素中
        div.html(content)
    </script>
</body>

</html>